import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/Index.vue'
import HomeMain from '../views/HomeMain.vue'
import ProDetail from '../views/ProDetail.vue'
import ProList from '../views/ProList.vue'

const routes = [
  {
    path: '/',
    component: Index,
    meta: {
      title: 'Sharein',
    },
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: HomeMain,
      },
      {
        path: 'nav',
        component: ProList,
      },
      {
        path: 'share',
        component: ProList,
      },
      {
        path: 'new',
        component: ProList,
      },
      {
        path: 'account',
        component: ProList,
      },
    ],
  },
  {
    path: '/pro-detail',
    component: ProDetail,
  },
  {
    path: '/pro-list',
    component: ProList,
  },
]
const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, _from, next) => {
  document.title = to.meta.title || 'Sharein'
  next()
})

export default router
